package com.lc.demo.mapper;

import com.lc.demo.bean.StuTestInformation;
import com.lc.demo.bean.TeaTestInformation;
import com.lc.demo.bean.deskInformation;
import com.lc.demo.bean.test;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TestMapper {
    @Select("select * from testmanagement")
    List<test> getAllTest();

    @Select("select * from testmanagement where test_id=#{testId}")
    test SelectATest(@Param("testId") String testId);

    @Update("update testmanagement set course_name=#{courseName} , credit=#{credit}" +
            " , class_name=#{className} , end_time=#{endTime} , test_date=#{testDate} , test_time=#{testTime},tea_id=#{teaId}" +
            " where test_id=#{testId}")
    void UpdateATest(@Param("testId") String testId, @Param("courseName") String courseName,
                     @Param("credit") int credit, @Param("className") String className,
                     @Param("endTime") String endTime, @Param("testDate") String testDate, @Param("testTime") String testTime,@Param("teaId") String teaId);

    @Delete("delete from testmanagement where test_id=#{testId}")
    void DeleteATest(@Param("testId") String testId);
    @Insert("insert into testmanagement(test_id,course_name,credit,class_name,end_time,test_date,test_time,tea_id) values" +
            " (#{testId},#{courseName} , #{credit}" +
            " ,#{className} ,#{endTime} ,#{testDate} ,#{testTime},#{teaId})")
    void AddATest(@Param("testId") String testId, @Param("courseName") String courseName,
                  @Param("credit") int credit, @Param("className") String className,
                  @Param("endTime") String endTime, @Param("testDate") String testDate, @Param("testTime") String testTime,@Param("teaId") String teaId);
    @Select("select * from testmanagement where test_id=#{testId}")
    List<test> getTestById(@Param("testId") String testId);
    @Select("select test_id,course_name,class_name,test_date,test_time from testmanagement where tea_id=#{teaId}")
    List<TeaTestInformation> TeaTestInformation(@Param("teaId") String teaId);
    @Select("select test_id,stugototest.course_name,test_date,test_time,desk_id from stugototest,student,testmanagement where student.stu_id=stugototest.stu_id and student.stu_class=testmanagement.class_name and student.stu_id=#{stuId} and testmanagement.course_name=stugototest.course_name")
    List<StuTestInformation> StuGoToTest(@Param("stuId") String stuId);
    @Select("select stugototest.desk_id,student.stu_id,stu_name from student,stugototest,testmanagement where student.stu_id=stugototest.stu_id and student.stu_class=testmanagement.class_name  and testmanagement.course_name=stugototest.course_name and test_id=#{testId}")
    List<deskInformation> GetDeskInformation(@Param("testId") String testId);
    @Insert("insert into stugototest(stu_id,desk_id,course_name) values" +
            " (#{stuId},#{deskId},#{courseName})")
    void AddDeskInformation(@Param("deskId") String deskId,@Param("stuId") String stuId,@Param("courseName") String courseName);
    @Select("select stugototest.desk_id,student.stu_id,stu_name from student,stugototest,testmanagement where student.stu_id=stugototest.stu_id and student.stu_class=testmanagement.class_name  and testmanagement.course_name=stugototest.course_name and test_id=#{testId} and desk_id=#{deskId}")
    List<deskInformation> SelectADesk(@Param("deskId") String deskId,@Param("testId") String testId);
    @Delete("delete from stugototest where desk_id=#{deskId} and stu_id in (select stu_id from student where stu_class=(select class_name from testmanagement where test_id=#{testId}))")
    void deleteDeskId(@Param("testId") String testId,@Param("deskId") String deskId);
}
